import os
from datetime import datetime

class GitAutoCommit:
    def __init__(self, directory):
        self.directory = directory


    def job(self):
        # 获取当前时间
        curtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        os.chdir(self.directory)
        os.system('git add .')
        com_line = f'git commit -m "{curtime}"'
        os.system(com_line)
        os.system('git push -u origin master')

if __name__ == '__main__':
    # 设置要操作的目录和间隔时间（秒）drwxr-xr-x. 2 root root 6 Oct 27 23:44 testdir
    directory = 'C:/custom/yd'
    auto_commit = GitAutoCommit(directory)
    auto_commit.job()